package com.example.shixi.controller;

import com.example.shixi.domain.BlogArticle;
import com.example.shixi.domain.BlogArticleType;
import com.example.shixi.service.ArticleService;
import com.example.shixi.service.LogService;
import com.example.shixi.service.UserService;
import com.example.shixi.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private LogService logService;
    @Autowired
    private ArticleService articleService;
    @GetMapping("/query/{pageNum}/{pageSize}")
    public JSONResult query(BlogArticle ba, @PathVariable Integer pageNum, @PathVariable Integer pageSize,String updateUserName){
        logService.add(updateUserName, "查看文章列表");
        return articleService.query(ba,pageNum,pageSize);
    }
    @PostMapping("/add")
    public JSONResult add(@RequestBody BlogArticle ba,String updateUserName){
        logService.add(updateUserName, "增加文章");
        return articleService.add(ba);
    }
    @ DeleteMapping("/del/{id}")
    public JSONResult del(@PathVariable Long id,String updateUserName){
        logService.add(updateUserName, "删除文章");
        return articleService.del(id);
    }
    @PutMapping("/update")
    public JSONResult update(@RequestBody BlogArticle ba,String updateUserName){
        logService.add(updateUserName, "更新文章");
        return articleService.update(ba);
    }
}
